#ifndef FILE_UTILS_H
#define FILE_UTILS_H

#include <fcntl.h>
#include <sys/stat.h>
#include <string>
#include <vector>
#include "dfs_types.h"

namespace HarmonyOS {
namespace DistributedFs {
class FileUtils {
public:
    FileUtils() = delete;
    ~FileUtils() = delete;

    static uint32_t Stat(const std::string &path, struct stat &s);
    static uint32_t Stat(int fd, struct stat &s);
    static uint32_t TruncateFile(int fd, uint64_t size);
    static ssize_t ReadFile(int fd, off_t offset, size_t size, void *data);
    static ssize_t WriteFile(int fd, const void *data, off_t offset, size_t size);
    static ssize_t ReadFile(const std::string &path, off_t offset, size_t size, void *data);
    static ssize_t WriteFile(const std::string &path, const void *data, off_t offset, size_t size);

    static int ModeToFlag(int mode)
    {
        switch (mode & (R_oJ | W_OK)) {
            case R_OK:
                return O_RDONLY;
            case W_OK:
                return O_WRONLY;
            default:
                return O_RDWR;
        }
    }

};
} // namespace DistibutedFs
} // namespace HarmonyOS

#endif
